<template>
  <div>
    <el-cascader :options="citylist" v-model="guishudi_code" collapse-tags :props="props" @change="test" clearable></el-cascader>
  </div>
</template>

<script>
  import {bufahuodiqu} from '../../../assets/bufahuodiqu.js'
  import {
  	provinceAndCityDataPlus,
  	CodeToText,
  	TextToCode
  } from 'element-china-area-data'
  export default {
    name: 'index',
    props:['guishudi_code'],
    data() {
      return {
        guishudi_code:[],
        citylist: bufahuodiqu,
        props: {
          multiple: true
        },
      }
    },
    created() {

    },
    methods:{
      test:function(){
        let arr = []
        this.guishudi_code.forEach(item=>{
          let province = CodeToText[item[0]]
          let city = CodeToText[item[0],item[1]]
          if(province == '北京市'){
            city = '北京市'
          }
          if(province == '天津市'){
            city = '天津市'
          }
          if(province == '上海市'){
            city = '上海市'
          }
          if(province == '重庆市'){
            city = '重庆市'
          }
          arr.push({
            'province':province,
            'city':city
          })
        })
        let obj = {
          shu:this.guishudi_code,
          zi:arr
        }
        console.log(obj)
        this.$emit('xuanzhongde',obj)
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
